package com.qfedu.edu.service.impl;

import com.qfedu.edu.constance.Constance;
import com.qfedu.edu.service.IJwtService;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jws;
import io.jsonwebtoken.Jwts;

/**
 * @author xiaobobo
 * @title: JwtService
 * @projectName cd-fy-2401-third-project-parent
 * @description: TODO
 * @date 2024/9/13  15:33
 */
public class JwtService implements IJwtService {

    //签名
    private String sign;

    public void setSign(String sign) {
        this.sign = sign;
    }


    @Override
    public String getUserId(String token) {
        Jws<Claims> jws = Jwts.parser()
                .setSigningKey(sign)
                .parseClaimsJws(token);
        String id = jws.getBody().getId();
        return id;
    }

    @Override
    public String getUsername(String token) {
        Jws<Claims> jws = Jwts.parser()
                .setSigningKey(sign)
                .parseClaimsJws(token);
        return jws.getBody().getSubject();
    }
}
